package org.example.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.domain.po.ErpSupplier;
import org.example.service.ErpSupplierService;
import org.example.mapper.ErpSupplierMapper;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
* @author 14120
* @description 针对表【erp_supplier(供应商/客户/会员表)】的数据库操作Service实现
* @createDate 2024-10-22 15:26:30
*/
@Service
public class ErpSupplierServiceImpl extends ServiceImpl<ErpSupplierMapper, ErpSupplier>
    implements ErpSupplierService{

    public List<ErpSupplier> selectByExample(){
        return this.baseMapper.selectByExample();
    }
    public List<ErpSupplier> selectByExample2(){
        return this.baseMapper.selectByExample2();
    }
    public List<ErpSupplier> selectByExample3(){
        return this.baseMapper.selectByExample3();
    }

    //分页条件查询
    @Override
    public Page<ErpSupplier> findByPage(Page<ErpSupplier> page, String supName, String supPhonenumber, String supContactnumber,Integer supType, Long tenantId) {
        return baseMapper.findByPage(page, supName, supPhonenumber, supContactnumber, supType, tenantId);
    }

    @Override
    public boolean modifyTheState(List<Integer> ids, String status) {
        return lambdaUpdate().set(ErpSupplier::getStatus, status).in(ErpSupplier::getSupId, ids).update();
    }

    @Override
    public List<ErpSupplier> findSupplier(Integer supType) {
        return baseMapper.findSupplier(supType);
    }

    @Override
    public List<ErpSupplier> findSuppliers() {
        return baseMapper.findSuppliers();
    }


    @Override
    public List<ErpSupplier> findSupplier3() {
        return baseMapper.findSupplier3();
    }
    public List<ErpSupplier>findBy(){
        return this.baseMapper.findBy();
    }
    
    @Override
    public List<ErpSupplier> findMember(Long tenantId, Integer subType) {
        return lambdaQuery().eq(ErpSupplier::getTenantId, tenantId)
                .eq(ErpSupplier::getSupType, subType)
                .list();
    }
    
    @Override
    public List<ErpSupplier> findMemberAndType(Long tenantId, List<Long> subType) {
        List<ErpSupplier> list = lambdaQuery().eq(ErpSupplier::getTenantId, tenantId)
                .in(ErpSupplier::getSupType, subType)
                .list();
        if (subType.size() > 1){
            list.forEach(item -> {
                if (item.getSupType().equals("0")){
                    item.setSupName(item.getSupName() + "[供应商]");
                } else if (item.getSupType().equals("1")){
                    item.setSupName(item.getSupName() + "[客户]");
                }
            });
        }
        return list;
    }
}




